"""参数类"""
import numpy as np

__all__ = ['Param', 'analysis_param']


class Param:
    """
    参数类
    """

    def __init__(self, dtype: type, min_val: str or float = None, max_val: str or float = None,
                 default: str or float = None, choices: list[int or float, ...] = None, step: int or float = None):
        """
        构造器
        :param dtype: 数据类型
        :param min_val: 最小值
        :param max_val: 最大值
        :param default: 默认值
        :param choices: 可选择范围
        """
        self.dtype = dtype
        self.choices = choices
        self.min = min_val
        self.max = max_val
        self.default = default
        self.step = step

def analysis_param(par: Param) -> list:

    if par.default is not None:
        return [par.default]
    elif par.choices is not None:
        return par.choices
    else:
        if par.dtype == int:
            _min = par.dtype(par.min)
            _max = par.dtype(par.max)
            if par.step is None:
                step = 1
            else:
                step = par.step
            v = list(range(_min, _max + 1, step))
        elif par.dtype == float:
            _min = par.dtype(par.min)
            _max = par.dtype(par.max)
            n = max(len(str(_max).split('.')[1]), len(str(_min).split('.')[1]))
            n = int('1' + '0' * n)
            if par.step is None:
                step = 1 / n
            else:
                step = par.step
            v = list(np.arange(_min, _max + 1 / n, step))
        else:
            raise
        return v

